/**
 * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hjb.toolbardemo.application;

import android.app.Activity;
import android.app.Application;

import com.hjb.toolbardemo.base.BaseActivity;
import com.okhttpfinal.OkHttpFinal;
import com.okhttpfinal.OkHttpFinalConfiguration;

import java.util.ArrayList;



/**
 * 作者 : hjb
 * 时间 : 2016/4/25.
 */
public class MyApplication extends Application {

    public static MyApplication instance;

    /**
     * Activity集合
     */
    private static ArrayList<BaseActivity> activitys = new ArrayList<BaseActivity>();
    private OkHttpFinalConfiguration.Builder builder;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        init();
        builder = new OkHttpFinalConfiguration.Builder();
        builder.setDebug(true);
        OkHttpFinal.getInstance().init(builder.build());
    }

    /**
     * 添加Activity到ArrayList<Activity>管理集合
     *
     * @param activity
     */
    public void addActivity(BaseActivity activity) {
        String className = activity.getClass().getName();
        for (Activity at : activitys) {
            if (className.equals(at.getClass().getName())) {
                activitys.remove(at);
                break;
            }
        }
        activitys.add(activity);
    }

    /**
     * 初始化
     */
    private void init() {

    }

    public static MyApplication getInstance() {
        return instance;
    }

}
